package org.oschina.api.manage.module.controller;

import java.util.List;
import org.oschina.api.BaseController;
import org.oschina.api.manage.module.service.ModuleService;
import org.oschina.api.manage.module.service.ModuleTypeService;
import org.oschina.api.manage.module.vo.ModuleTypeVo;
import org.oschina.api.manage.module.vo.ModuleVo;
import org.oschina.config.Config;
import org.oschina.handler.validator.annotation.Validate;
import org.oschina.handler.validator.annotation.ValidateField;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(value=Config.API_PATH+"/manage/module")
public class ModuleController extends BaseController {

	@Autowired
	private ModuleService moduleService;
	@Autowired
	private ModuleTypeService moduleTypeService;
	
	/**
	 * 根据类型返回模块
	 * @param type
	 * @return
	 */
	@Validate
	@RequestMapping(value="/type/{type}",method=RequestMethod.GET)
	public List<ModuleVo> findVoByType
	(
		@PathVariable @Validate(validateField=@ValidateField(validateValue=true,min=1)) Integer type
	)
	{
		return moduleService.findVoByType(type);
	}
	
	/**
	 * 返回模块类型
	 * @return
	 */
	@Validate
	@RequestMapping(value="/type",method=RequestMethod.GET)
	public List<ModuleTypeVo> findType()
	{
		return moduleTypeService.findVo();
	}
}